package cn.dglydrpy.fundmanagement.controller;

import cn.dglydrpy.fundmanagement.service.IInvestmentGoalService;
import cn.dglydrpy.fundmanagement.service.dto.InvestmentGoalDto;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/investmentGoals")
public class InvestmentGoalController {

    @Autowired
    private IInvestmentGoalService investmentGoalService;

    @PostMapping("/addInvestmentGoal")
    public void addInvestmentGoal(@RequestBody InvestmentGoalDto investmentGoalDto) {
        investmentGoalService.saveInvestmentGoal(investmentGoalDto);
    }

    @PostMapping("/updateInvestmentGoal")
    public void updateInvestmentGoal(@RequestBody InvestmentGoalDto investmentGoalDto) {
        investmentGoalService.updateInvestmentGoal(investmentGoalDto);
    }

    @PostMapping("/deleteInvestmentGoal/{id}")
    public void deleteInvestmentGoal(@PathVariable Long id) {
        investmentGoalService.deleteInvestmentGoal(id);
    }

    @GetMapping("/{id}")
    public InvestmentGoalDto getInvestmentGoalById(@PathVariable Long id) {
        return investmentGoalService.getInvestmentGoalById(id);
    }

    @GetMapping("/getInvestmentGoalsByConditions")
    public Page<InvestmentGoalDto> getInvestmentGoalsByConditions(
            @RequestParam String portfolioId,
            @RequestParam String goalType,
            @RequestParam String achieved,
            @RequestParam int pageNo,
            @RequestParam int pageSize) {
        return investmentGoalService.getInvestmentGoalsByConditions(portfolioId, goalType, achieved, pageNo, pageSize);
    }

    @GetMapping("/getAllInvestmentGoals")
    public List<InvestmentGoalDto> getAllInvestmentGoals() {
        return investmentGoalService.getAllInvestmentGoals();
    }

    @PostMapping("/checkAndSendReminders")
    public void checkAndSendReminders() {
        investmentGoalService.checkAndSendReminders();
    }
}